package com.dlc.shop.systemtest.api.amount;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dlc.shop.bean.model.OfflineHandleEvent;
import com.dlc.shop.bean.param.OfflineHandleEventAuditParam;
import com.dlc.shop.common.util.Json;
import com.dlc.shop.common.util.PageParam;
import com.dlc.shop.distribution.common.dto.DistributionProdDto;
import com.dlc.shop.distribution.common.model.DistributionProd;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author: zsm
 * @date: 2023/2/28 9:40
 */
public class DistributionProdApi {

    /**
     * 分页查看分销商品
     * @param shopId 店铺id
     * @param prodName 商品名
     * @param sort 排序(1时间排序 2销量排序 3价格排序) 默认1
     * @param orderBy 排序(0升序 1降序) 默认1
     * @param page
     * @return
     */
    public static void page(@RequestParam(value = "shopId", required = false, defaultValue = "0") Long shopId,
                            @RequestParam(value = "prodName", required = false) String prodName,
                            @RequestParam(value = "sort", defaultValue = "1") Integer sort,
                            @RequestParam(value = "orderBy", defaultValue = "1") Integer orderBy,
                            PageParam<DistributionProdDto> page){
        String url = Constant.API_URL + "/p/distribution/prod/page" + "?shopId=" + shopId + "&prodName=" + prodName + "&sort=" + sort + "&orderBy=" + orderBy;
         HttpUtil.get(url);
    }

    /**
     * 新增分销商品
     */
    public static void savaDistributionProd(DistributionProd distributionProd){
        String url = Constant.SHOP_URL + "/distribution/distributionProd";
        HttpUtil.post(url, distributionProd);

    }

    /**
     * 商家分页获取分销商品列表
     */
    public static List<DistributionProd> getDistributionProdPage(){
        String url = Constant.SHOP_URL + "/distribution/distributionProd/page";
        return JSON.parseArray(JSON.toJSONString(Json.parseObject(JSON.toJSONString(HttpUtil.get(url, Page.class)), Page.class).getRecords()), DistributionProd.class);
    }

    /**
     * 根据分销商品id查看分销商品数据
     * @param id
     */
    public static DistributionProd info(@PathVariable("id") Long id){
        String url = Constant.SHOP_URL + "/distribution/distributionProd/info/" + id;
       return HttpUtil.get(url, DistributionProd.class);
    }

    /**
     * 修改分销商品
     */
    public static void updateDistributionProd(DistributionProd distributionProd) {
        String url = Constant.SHOP_URL + "/distribution/distributionProd";
        HttpUtil.put(url, distributionProd);
    }

    /**
     * 删除分销商品
     */
    public static void deleteDistributionProd(List<Long> ids) {
        String url = Constant.SHOP_URL + "/distribution/distributionProd";
        HttpUtil.delete(url, ids);
    }

    /**
     * 平台违规下架分销商品
     */
    public static void offline(OfflineHandleEvent offlineHandleEvent) {
        String url = Constant.PLATFORM_URL + "/platform/distributionProd/offline";
        HttpUtil.post(url, offlineHandleEvent);
    }

    /**
     * 商家根据分销商品ID获取下架信息
     */
    public static OfflineHandleEvent getOfflineHandleEvent(Long id) {
        String url = Constant.SHOP_URL + "/distribution/distributionProd/getOfflineEventByDistProdId/" + id;
        return HttpUtil.get(url, OfflineHandleEvent.class);
    }

    /**
     * 商家申请上架分销商品
     */
    public static void auditApply(OfflineHandleEventAuditParam offlineHandleEventAuditParam) {
        String url = Constant.SHOP_URL + "/distribution/distributionProd/auditApply";
        HttpUtil.post(url, offlineHandleEventAuditParam);
    }

    /**
     * 平台根据分销商品ID获取下架信息
     */
    public static OfflineHandleEvent platformGetOfflineHandleEvent(Long id) {
        String url = Constant.PLATFORM_URL + "/platform/distributionProd/getOfflineEventByDistProdId/" + id;
        return HttpUtil.get(url, OfflineHandleEvent.class);
    }

    /**
     * 平台审核申请
     */
    public static void audit(OfflineHandleEventAuditParam offlineHandleEventAuditParam) {
        String url = Constant.PLATFORM_URL + "/platform/distributionProd/auditDistributionProd";
        HttpUtil.post(url, offlineHandleEventAuditParam);
    }


}
